﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AccountManagement
{
    class Management
    {
        List<Account> al;
        public Management()
        {
            al = new List<Account>();
        }

        public void AddAccount(string type, string name)
        {
            Account account;
            switch (type) {
                case ("A"):
                    account = new Account(name, 1000);
                    al.Add(account);
                    break;
                case ("B"):
                    double money = 0;
                    foreach (Account item in al)
                        money += item.Discount();
                    account = new Account(name, money);
                    al.Add(account);
                    break; 
            }
            Console.WriteLine("新建账户成功");
            
        }
        public void ShowAll()
        {
            foreach (Account item in al)
                item.Show();
        }

        public void RetrieveMoney(string name, string money)
        {
            foreach(Account item in al)
            {
                if (item.Name == name)
                {  
                    bool result = item.RetrieveMoney(double.Parse(money));
                    if (result) Console.WriteLine("成功取钱");
                    else Console.WriteLine("取钱失败，赶紧去赚钱吧");
                    return;
                }
            }
            Console.WriteLine("该用户不存在");
        }

        public void DeleteAccount(string name)
        {
            foreach(Account item in al)
            {
                if(item.Name == name)
                {
                    al.Remove(item);
                    Console.WriteLine("成功删除");
                }
            }
            Console.WriteLine("不存在该账户");
        }
    }
}
